package com.zzy.app.config;

import com.zzy.app.entity.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * 在IOCTest test1中研究@ComponentScan
 */
@Configuration
//@ComponentScan(value = "com.zzy")

//@ComponentScan(value = "com.zzy", excludeFilters = {
//        /**
//         * 通过排除包扫描，排除了PersonController
//         * type：指定你要排除的规则，是按照注解进行排除，还是按照给定的类型进行排除，还是按照正则表达式进行排除，等等
//         * classes：除了@Controller和@Service标注的组件之外，IOC容器中剩下的组件我都要，即相当于是我要排除@Controller和@Service这俩注解标注的组件。
//         */
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class, Service.class})})

////ComponentScan注解类的内部只声明了一个返回ComponentScan[]数组的value()方法，代表它是一个重复注解
////java8之前他不是重复注解，但是可以用@ComponentScans完成相同功能
//@ComponentScan(value = "com.zzy", includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})
//        //当使用includeFilters()方法来指定只包含哪些注解标注的类时，需要禁用掉默认的过滤规则
//}, useDefaultFilters = false)
//
//@ComponentScan(value = "com.zzy", includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
//        //当使用includeFilters()方法来指定只包含哪些注解标注的类时，需要禁用掉默认的过滤规则
//}, useDefaultFilters = false)

@ComponentScan(value = "com.zzy", includeFilters = {
        //自定义@ComponentScan.Filter
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {ComponentScanTypeFilter.class})
}, useDefaultFilters = false)
public class MainConfig {
    @Bean(name = "person2")
    public Person person1() {
        return new Person("zzy", 28);
    }
}
